/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package libudp;

import java.io.Serializable;

/**
 * The Ack object encapsulates a datagram message which acknowledges a server
 * received a message to a client application. 
 * 
 * The Ack object implements Serializable. This allows client applications to
 * serialize Ack object to bytes and deserialize bytes to Ack objects.
 * @author davidmessing
 */
public class Ack implements Serializable {
    
    private long timeClient;  // time in milliseconds that the Syn was created
    private long timeServer;  // time in milliseconds that the Ack was created
    private int sequenceNum;    // Acks's return the next sequence number expected
    private String message; // Ack's return a short a message

    //<editor-fold defaultstate="collapsed" desc="Getters and Setters">
    /**
     * Returns the Ack object's short message.
     * @return
     */
    public String getMessage() {
        return message;
    }
    
    /**
     * Sets an Ack's short message.
     * @param message
     */
    public void setMessage(String message) {
        this.message = message;
    }
    
    /**
     * Returns an Ack's sequence number.
     *  This is the next sequence number expected at the server.
     * @return
     */
    public int getSequenceNum() {
        return sequenceNum;
    }
    
    /**
     * Sets the Acks sequence number.
     * This is the next sequence number expected at the server.
     * @param sequenceNum
     */
    public void setSequenceNum(int sequenceNum) {
        this.sequenceNum = sequenceNum;
    }
    
    /**
     * Returns the client's time encapsulated in the Ack object.
     * @return
     */
    public long getTimeClient() {
        return timeClient;
    }
    
    /**
     * Set's the client time in Ack object.
     * @param timeClient
     */
    public void setTimeClient(long timeClient) {
        this.timeClient = timeClient;
    }
    
    /**
     * Returns the server's time encapsulated in the Ack object.
     * @return
     */
    public long getTimeServer() {
        return timeServer;
    }
    
    /**
     * Set's the client time in Ack object.
     * @param timeServer
     */
    public void setTimeServer(long timeServer) {
        this.timeServer = timeServer;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Constructors">
    /**
     *
     */
    public Ack() {
        timeClient = System.currentTimeMillis();
        timeServer = System.currentTimeMillis();
        sequenceNum = 0;
        message = "ACK";
    }
    
    /**
     *
     * @param timeClient
     * @param timeServer
     * @param sequenceNum
     * @param message
     */
    public Ack(long timeClient, long timeServer, int sequenceNum, String message) {
        this.timeClient = timeClient;
        this.timeServer = timeServer;
        this.sequenceNum = sequenceNum;
        this.message = message;
    }
    //</editor-fold>

    @Override
    public String toString() {
        return "ACK{" + "tc1=" + timeClient + ", ts=" + timeServer + ", sequenceNumRequest=" + sequenceNum + '}';
    } 
}
